package com.hyfrogx.modules.manage.service.course.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hyfrogx.common.exception.MyException;
import com.hyfrogx.common.utils.Query;
import com.hyfrogx.common.utils.QueryExt;
import com.hyfrogx.modules.manage.dao.course.CourseManageRemarkDao;
import com.hyfrogx.modules.manage.entity.course.CourseManageRemarkEntity;
import com.hyfrogx.modules.manage.service.course.CourseManageRemarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author 罗春杰-技术部
 */
@Service
public class CourseManageRemarkServiceImpl extends ServiceImpl<CourseManageRemarkDao, CourseManageRemarkEntity> implements CourseManageRemarkService {


    @Override
    public List<CourseManageRemarkEntity> ListGetTenRemark(Integer courseId) {
        List<CourseManageRemarkEntity> result = this.baseMapper.ListGetTenRemark(courseId);
        return result;
    }

    @Override
    public Page ListGetPageRemarkForStatus(QueryExt queryExt) {
        Map map  = new HashMap();
        map.putAll(queryExt.getCondition());
        if(map.get("courseId")==null && ObjectUtil.isEmpty(map.get("courseId"))){
            throw new MyException("课程Id不能为空");
        }
        List<CourseManageRemarkEntity> result = this.baseMapper.ListGetPageRemarkForStatus(map, queryExt);
        if (result == null){
            throw  new MyException("暂无评论");
        }
        queryExt.setRecords(result);
        return queryExt;
    }

    @Override
    public double  sunGrade(Integer CourseId) {
        double sunGrade =this.baseMapper.sunGrade(CourseId);
        return sunGrade;
    }

    @Override
    public Page ListGetPageRemark(QueryExt queryExt) {
        Map map = new HashMap();
        map.putAll(queryExt.getCondition());
        queryExt.setRecords(this.baseMapper.ListGetPageRemark(map, queryExt));
        return queryExt;
    }
}
